import java.util.Scanner;

/**
 * @Title: 排列数字
 * @Author 贾金博
 * @Package PACKAGE_NAME
 * @Date 2024/3/14 19:46
 * @description:
 */
public class 排列数字 {
    public static  int[] a = new int[10];
    public static boolean[] st = new boolean[10];
    public static int n;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        dfs(1);
    }

    public static void dfs(int len) {
        if(len == n + 1) {
            for(int i = 1; i <= n; ++ i ) {
                System.out.print(a[i] + " ");
            }
            System.out.println();
            return;
        }
        for(int i = 1; i <= n; ++ i ) {
            if(!st[i]) {
                st[i] = true;
                a[len] = i;
                dfs(len + 1);
                //记得回溯
                st[i] = false;
            }
        }
    }
}
